package com.scu.servlet;


import com.scu.utils.JDBCUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException  {

        request.setCharacterEncoding("utf-8");
        //1.获得用户的用户名和密码
        String user_id = request.getParameter("user_id");
        int user_id_int = Integer.parseInt(user_id);
        String password = request.getParameter("password");

        try {
            //1. 连接
            Connection conn = JDBCUtil.getConnection();

            //2. sql
            String sql = "select * from user where user_id=?";
            PreparedStatement prep = conn.prepareStatement(sql);
            prep.setInt(1,user_id_int);

            ResultSet rs = prep.executeQuery();
            String password_ = rs.getString("password");


            if(password.equals(password_)){
                //进入首页
            }else{
                //弹窗提示
            }


        } catch (SQLException e) {
            e.printStackTrace();
        }

    }

}
